#include "types.h"
#include "list.h"
#include <memory.h>
#include <malloc.h>

//------------------------------------------------------------------
//	object-independent doubly-linked list
//------------------------------------------------------------------
//	item management
//------------------------------------------------------------------
#define ALLOCITEM_SIZE		(256)

u32			TIListItem::s_numClients = 0;
TIListItem	TIListItem::s_allocedItems;
TIListItem	TIListItem::s_freeItems;


void TIListItem::AllocItems()
{
	TIListItem	*alloced;
	u32			size = ALLOCITEM_SIZE*sizeof(TIListItem);
	u32			i;
	
	alloced = (TIListItem*)malloc(size);
	memset(alloced,0,size);

	TList::InsertAfter(alloced,&s_allocedItems);
	for( i=1;i<ALLOCITEM_SIZE;i++ )
	{
		TList::InsertAfter(&alloced[i],&s_freeItems);
	}
}

void TIListItem::FreeItems()
{
	TIListItem	*alloced;

	while( (alloced=TList::GetNext(&s_allocedItems))!=&s_allocedItems )
	{
		TList::Remove(alloced);
		free(alloced);
	}
}
